package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.InternalTransfer;
import com.amsp.oa.oademo.service.InternalTransferService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "内部调动审批表接口")
@RestController
@RequestMapping("/api/transfer")
public class InternalTransferController {

    @Autowired
    private InternalTransferService transferService;

    @ApiOperation("分页查询内部调动记录")
    @GetMapping("/page")
    public IPage<InternalTransfer> getPage(
            @ApiParam("页码") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam("每页数量") @RequestParam(defaultValue = "10") Integer pageSize,
            @ApiParam("关键字") @RequestParam(required = false) String keyword) {
        return transferService.getPage(pageNum, pageSize, keyword);
    }

    @ApiOperation("获取内部调动记录详情")
    @GetMapping("/{id}")
    public InternalTransfer getById(@PathVariable Long id) {
        return transferService.getTransferWithDetails(id);
    }

    @ApiOperation("保存内部调动记录")
    @PostMapping("/save")
    public boolean save(@RequestBody InternalTransfer transfer) {
        return transferService.saveTransferWithDetails(transfer);
    }

    @ApiOperation("删除内部调动记录")
    @DeleteMapping("/{id}")
    public boolean removeById(@PathVariable Long id) {
        return transferService.removeById(id);
    }
}